<template>
  <a-card :body-style="{padding: '24px 32px'}" :bordered="false">
    <a-spin :spinning="loading">
      <a-form @submit="handleSubmit" :form="form">
        <a-form-item
          label="企业名称"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            v-decorator="[
              'enterpriseName',
              {rules: [{ required: true, message: '请输入企业名称' }]}
            ]"
            name="enterpriseName"
            placeholder="企业名称"
          />
        </a-form-item>
        <a-form-item
          label="统一社会信用代码"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            v-decorator="[
              'unifiedSocialCreditCode',
              {rules: [{ required: false, message: '请输入统一社会信用代码' }]}
            ]"
            name="unifiedSocialCreditCode"
            placeholder="统一社会信用代码"
          />
        </a-form-item>
        <a-form-item label="法人姓名:" 
        :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
            <a-input v-decorator="[
              'legalPersonName',
              {
                rules: [{ required: false, message: '请输入法人姓名' }, {
                  max: 10,
                  message: '不超过10个字'
                }]
              }
            ]" name="legalPersonName" placeholder="法人姓名" />
          </a-form-item>
          <a-form-item label="法人身份证号:" :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
            <a-input v-decorator="[
              'legalPersonIdcardNum',
              { rules: [{ required: false, message: '请输入法人身份证号' },
                        { min: 1,max: 18, message: '输入不能超过18个字符'}] 
              }
            ]" name="legalPersonIdcardNum" placeholder="法人身份证号" />
          </a-form-item>
        <a-form-item
          label="行业"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-cascader
            :options="treeData"
            :load-data="onLoadTreeOptionData"
            :fieldNames="treeFields"
            :placeholder="industryIdName || '行业'"
            change-on-select
            :display-render="displayRender"
            @change="setSelectRow"
            :getPopupContainer="(triggerNode) => triggerNode.parentNode"
          />
        </a-form-item>
        <a-form-item
          label="发票类型"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-select
            v-decorator="[
              'invoiceType',
              {rules: [{ required: true, message: '请选择发票类型' }]}
            ]"
            name="invoiceType"
            placeholder="请选择发票类型"
            @change="handleChange1"
            :getPopupContainer="(triggerNode) => triggerNode.parentNode"
          >
            <a-select-option :key="1">增值税普通发票</a-select-option>
            <a-select-option :key="2">增值税专用发票</a-select-option>
            <a-select-option :key="3">增值税差额普票</a-select-option>
            <a-select-option :key="4">增值税普通发票/增值税专用发票</a-select-option>
            <!-- <a-select-option :key="5">增值税专用发票/增值税差额普票</a-select-option> -->
          </a-select>
        </a-form-item>
        <a-form-item label="纳税人类型:" 
        :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
            <a-select @change="handleEnterpriseTypeChange" 
            :placeholder="'请选择纳税人类型'"
            v-decorator="['enterpriseType', {
              rules: [{ required: true, message: '请选择纳税人类型' }]
            }]"
            :getPopupContainer="(triggerNode) => triggerNode.parentNode"
            >
              <a-select-option value="小规模">小规模</a-select-option>
              <a-select-option value="一般纳税人">一般纳税人</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="税务登记证号:" 
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-input :maxLength="18" 
          placeholder="请输入税务登记证号"
          v-decorator="['comTaxNumber', {
            rules: [{ required: true, pattern: /^[A-Za-z0-9]{18}/, message: '请输入18位税务登记证号' }]
          }]" />
        </a-form-item>
        <a-form-item label="基本开户行:" 
        :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
            <a-input
            placeholder="请输入基本开户行"
            v-decorator="['bankName', {
              rules: [{ required: isNeedChecked, message: '请输入基本开户行' }]
            }]" />
          </a-form-item>
          <a-form-item label="基本开户账号:" 
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
            <a-input 
            placeholder="请输入基本开户账号"
            v-decorator="['bankNum', {
              rules: [{ required: isNeedChecked, message: '请输入基本开户账号' }]
            }]" />
          </a-form-item>
          <a-form-item label="注册固定电话:" 
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
            <a-input 
            placeholder="请输入注册固定电话"
            v-decorator="['phone', {
              rules: [{ required: isNeedChecked, message: '请输入注册固定电话' }]
            }]" />
          </a-form-item>
          <a-form-item label="注册场所地址:"  :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
            <a-input 
            placeholder="请输入注册场所地址"
            v-decorator="['unitAddress', {
              rules: [{ required: true, message: '请输入注册场所地址' }]
            }]" />
          </a-form-item>
        <a-form-item
          label="用户名"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            v-decorator="[
              'enterpriseSimpleName',
              {rules: [{ required: true, message: '请输入用户名' }, {
                max: 10,
                message: '不超过10个字'
              }]}
            ]"
            name="enterpriseSimpleName"
            placeholder="用户名"
          />
        </a-form-item>
        <a-form-item
          label="邮箱"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            v-decorator="[
              'email',
              {rules: [{ required: true, type:'email', message: '请输入邮箱' }]}
            ]"
            name="email"
            placeholder="邮箱"
          />
        </a-form-item>
        <a-form-item
          label="联系人姓名"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            v-decorator="[
              'managerName',
              {rules: [{ required: false, message: '请输入联系人姓名' }]}
            ]"
            name="managerName"
            placeholder="联系人姓名"
          />
        </a-form-item>
        <a-form-item
          label="联系人手机号"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            v-decorator="[
              'managerPhone',
              {rules: [{ required: true, pattern: /^1[3456789]\d{9}$/, message: '请输入联系人手机号' }]}
            ]"
            name="managerPhone"
            placeholder="联系人手机号"
          />
        </a-form-item>
        <a-form-item
          label="运营人员"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-select
            v-decorator="[
              'operationsManagerId',
              {rules: [{ required: false, message: '请输入运营人员姓名' }]}
            ]"
            name="operationsManagerName"
            placeholder="运营人员姓名"
            @change="handleChange"
            :getPopupContainer="(triggerNode) => triggerNode.parentNode"
            show-search 
            :filter-option="yunyingFilterOption"
            >
            <a-select-option
              v-for="item in yyOptions"
              :key="item.userId">
              {{ item.realName }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="销售人员"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            v-decorator="[
              'salesName',
              {rules: [{ required: false, message: '请输入销售人员姓名' }]}
            ]"
            name="salesName"
            placeholder="销售人员姓名"
          />
        </a-form-item>
        <a-form-item
          label="风险评分"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            type="number"
            v-decorator="[
              'riskScore',
              {rules: [{ required: false, message: '请输入风险评分' }]}
            ]"
            name="riskScore"
            placeholder="风险评分"
          />
        </a-form-item>
        <a-form-item
          label="风险星级"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            type="number"
            v-decorator="[
              'riskStar',
              {rules: [{ required: false, message: '请输入风险星级' }]}
            ]"
            name="riskStar"
            placeholder="风险星级"
          />
        </a-form-item>

        <a-form-item
          label="项目审核"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-radio-group
            v-decorator="['needAudit', {
              initialValue: false
            }]"
          >
            <a-radio :value="true">是</a-radio>
            <a-radio :value="false">否</a-radio>
          </a-radio-group>
        </a-form-item>

        <a-form-item
          label="合同扫描件"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <div v-if="form.getFieldValue('contractScanCopy')">
            <a
              @click="imageUrlPrefix +form.getFieldValue('contractScanCopy')"
            >{{ form.getFieldValue('contractScanCopy') }}</a>
            <span>
              &nbsp;
              <a-icon type="close" @click="removeFile" />
            </span>
          </div>
          <a-upload
            v-else
            name="mediaFile"
            :showUploadList="false"
            :before-upload="beforeUploadFile"
          >
            <a-button :loading="uploadLoading">
              <a-icon type="upload" />添加
            </a-button>
          </a-upload>
          <a-input
            hidden
            v-decorator="[
              'contractScanCopy',
              {rules: [{ required: false, message: '请上传合同扫描件' }]}
            ]"
          />
        </a-form-item>

        <!-- <a-form-item
          label="账单方式"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-radio-group
          :disabled="isEdit"
          v-decorator="['feeMode', {
              initialValue: 2
            }]">
            <a-radio :value="1">开票金额</a-radio>
            <a-radio :value="2">实发金额</a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item
          label="费率类型"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-radio-group
            :disabled="isEdit"
            v-decorator="['feeRateType', {
              initialValue: 1
            }]"
            @change="setFeeRateType"
          >
            <a-radio :value="1">固定</a-radio>
            <a-radio :value="2">阶梯</a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item
          v-if="feeRateType === 1"
          label="服务费率"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input-number
            :min="1"
            :max="20"
            :step="1"
            :disabled="isEdit"
            :formatter="value => `${value}%`"
            :parser="value => value.replace('%', '')"
            placeholder="服务费率"
            style="width: 100%;"
            v-decorator="[
              'feeRate',
              {rules: [{ required: true, message: '请输入服务费率' }]}
            ]"
          />
        </a-form-item> -->

        <a-form-item
          label="月度个人限额"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
          name="limitList"
        >
          <a-table
            v-show="limitList.length"
            :columns="limitColumns"
            rowKey="limitName"
            :pagination="false"
            :data-source="limitList"
            size="small"
          >
            <span
              slot="action"
              slot-scope="text, record, index">
              <template>
                <a @click="deleteLimitRow(index)">删除</a>
              </template>
            </span>
          </a-table>
          <a-button
            type="primary"
            @click="showCollectionLimitModel">新增限额</a-button>
          <collection-create-limit-form
            :visible="collectionLimitFormVisable"
            ref="limitForm"
            @cancel="handleLimitCollectionCancel"
            @create="handleLimitCollectionCreate"
          />
        </a-form-item>

        <a-form-item
          label="供应商"
          required
          :help="serverValidator.help"
          :validate-status="serverValidator.status"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
          name="servers"
        >
          <a-table
            v-show="serverList.length"
            :columns="serverListColumns"
            rowKey="serverId"
            :pagination="false"
            :data-source="serverList"
            size="small"
          >
            <span
              slot="action"
              slot-scope="text, record, index">
              <template>
                <a @click="deleteServerRow(index)">删除</a>
              </template>
            </span>
          </a-table>
          <a-button
            type="primary"
            @click="showCollectionServerModel">新增供应商</a-button>
          <collection-create-server-form
            :visible="collectionServerFormVisable"
            ref="serverForm"
            @cancel="handleServerCollectionCancel"
            @create="handleServerCollectionCreate"
          />
        </a-form-item>
        <a-form-item label="供应商费率" required 
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 12}, sm: {span: 17} }"
          name="enterpriseServerFeeRateList">
          <a-table v-show="serverFeeList.length" :columns="gysflColums" :rowKey="(record,index)=>{return index}" :pagination="false"
            :data-source="serverFeeList" size="small">
            <span
              slot="feeMode"
              slot-scope="text">
              <template>
                <span v-if="text == 1">开票金额</span>
                <span v-if="text == 2">实发金额</span>
              </template>
            </span>
            <span
              slot="feeRateType"
              slot-scope="text">
              <template>
                <span v-if="text == 1">固定</span>
                <span v-if="text == 2">阶梯</span>
              </template>
            </span>
            <span
              slot="feeRate"
              slot-scope="text, record, index">
              <template v-if="record.feeRateType == 1">
                <span>{{text}}%</span>
              </template>
              <template v-if="record.feeRateType == 2">
                <a @click="serverName = record.serverName, 
                newFeeRateRangeList = record.feeRateList, 
                currentIndex = index,
                showJieti = true">查看</a>
              </template>
            </span>
            <span
              slot="taxRate"
              slot-scope="text">
              <template>
                <span v-if="text && text != '*'">{{ parseFloat((text * 100).toFixed(10)) }}%</span>
                <span v-else>{{ text }}</span>
              </template>
            </span>
            <span slot="action" slot-scope="text, record, index">
              <template>
                <a @click="editFeeRate(record, index)">编辑</a>
              </template>
              <a-divider type="vertical" />
              <template>
                <a @click="deleteServerFeeRow(record,index)">删除</a>
              </template>
              
              
            </span>
          </a-table>
          <a-button class="addBtn" type="primary" @click="showserverFeeFormVisable">新增供应商费率</a-button>
          <collection-create-server-fee-form :visible="collectionServerFeeFormVisable" ref="serverFeeForm"
            @cancel="handleLimitFeeFormCancel"
            @create="handleLimitFeeFormCreate"></collection-create-server-fee-form>
        </a-form-item>

        <!-- <a-form-item
          v-if="feeRateType === 2"
          label="阶梯费率"
          required
          :help="feeRangeValidator.help"
          :validate-status="feeRangeValidator.status"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-table
            v-show="feeRateRangeList.length"
            :columns="feeRateRangeColumns"
            rowKey="amountLow"
            :pagination="false"
            :data-source="feeRateRangeList"
            size="small"
          >
            <span slot="money" slot-scope="text">
              <span>{{ text | formatMoney }}</span>
            </span>
            <span slot="rate" slot-scope="text">
              <span>{{ (text * 100).toFixed(2) }}%</span>
            </span>
            <span slot="action" slot-scope="text, record, index">
              <template v-if="index === 0 || (index + 1) === feeRateRangeList.length">
                <a @click="deleteFeeRangeRow(index)" :disabled="isEdit">删除</a>
              </template>
            </span>
          </a-table>
          <a-button type="primary" @click="showCollectionModel" v-if="!isEdit">新增费率</a-button>
          <collection-create-form
            ref="collectionForm"
            :visible="collectionFormVisable"
            @cancel="handleCollectionCancel"
            @create="handleCollectionCreate"
          />
        </a-form-item> -->
        <!-- <a-form-item
          label="在线支付"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-switch
            checked-children="开通"
            un-checked-children="关闭"
            v-decorator="[
              'isOpenXbd', {
                valuePropName: 'checked',
                initialValue: false
              }
            ]"
          />
        </a-form-item> -->
        <!-- <a-form-item
          v-if="form.getFieldValue('isOpenXbd')"
          label="xbdUserUuid"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            v-decorator="[
              'userUuid',
              {rules: [{ required: true, message: '请输入xbdUserUuid' }]}
            ]"
            name="userUuid"
          />
        </a-form-item>
        <a-form-item
          v-if="form.getFieldValue('isOpenXbd')"
          label="xbdToken"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-input
            v-decorator="[
              'userToken',
              {rules: [{ required: true, message: '请输入xbdToken' }]}
            ]"
            name="userToken"
          />
        </a-form-item> -->
        <a-form-item
          label="企业状态"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
        >
          <a-radio-group v-decorator="['status', {
              initialValue: 1
            }]">
            <a-radio :value="1">正常</a-radio>
            <a-radio :value="0">冻结</a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item :wrapperCol="{ span: 24 }" style="text-align: center">
          <a-button htmlType="submit" type="primary">立即{{ pageTypeName }}</a-button>
        </a-form-item>
      </a-form>
    </a-spin>
    <price-form ref="priceInfo"></price-form>
    <a-modal :visible="showJieti"
        width="800px"
        title="阶梯费率"
        okText="确定"
        @cancel="showJieti = false"
        @ok="showJieti = false">
        <a-table
            :columns="feeRateRangeColumns"
            rowKey="amountLow"
            :pagination="false"
            :data-source="newFeeRateRangeList"
            size="small"
          >
            <span
              slot="money"
              slot-scope="text">
              <span>{{ text | formatMoney }}</span>
            </span>
            <span
              slot="rate"
              slot-scope="text">
              <span>{{ parseFloat((text * 100).toFixed(10)) }}%</span>
            </span>
          </a-table>
          <collection-create-form
            ref="collectionForm"
            :visible="collectionFormVisable"
            @cancel="handleCollectionCancel"
            @create="handleCollectionCreate"
          />
      </a-modal>
  </a-card>
</template>

<script>
  import {
    addEnterprise,
    updateEnterprise,
    getEnterpriseDetail,
    uploadProjectFile,
    getIndustry,
    getYYsysUsers,
    getServerFeeList
  } from '@/api/manage'
import CollectionCreateForm from './feeRange-Form'
import config from '@/config/defaultSettings'
import CollectionCreateServerFeeForm from './serverFee-Form.vue'
import CollectionCreateLimitForm from './limit-Form'
import CollectionCreateServerForm from './server-Form'
import priceForm from './priceForm'
import NP from 'number-precision'
import cloneDeep from 'lodash.clonedeep'
export default {
  name: 'EnterpriseAdd',
  components: {
    CollectionCreateForm,
    CollectionCreateServerForm,
    CollectionCreateLimitForm,
    CollectionCreateServerFeeForm,
    priceForm
    },
  data() {
    return {
      // description: '表单页用于向用户收集或验证信息，基础表单常见于数据项较少的表单场景。',
      form: this.$form.createForm(this),
      imageUrlPrefix: config.uploadedUrlPrefix,
      defaultFileList: [],
      uploadLoading: false,
      value: 1,
      treeData: [],
      treeFields: {
        children: 'children',
        label: 'industryName',
        value: 'industryId'
      },
      feeRateType: 1,
      collectionFormVisable: false,
      collectionLimitFormVisable: false,
      collectionServerFormVisable: false,
      collectionServerFeeFormVisable: false,
      serverValidator: {
        status: 'success'
      },
      feeRateRangeList: [],
      feeRangeValidator: {
        status: 'success'
      },
      hyId: '',
      feeRateRangeColumns: [
        {
          title: '最低金额',
          dataIndex: 'amountLow',
          scopedSlots: { customRender: 'money' }
        },
        {
          title: '最高金额',
          dataIndex: 'amountHigh',
          scopedSlots: { customRender: 'money' }
        },
        {
          title: '服务费率',
          dataIndex: 'feeRate',
          scopedSlots: { customRender: 'rate' }
        },
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   scopedSlots: { customRender: 'action' }
        // }
      ],

      limitList: [],
      limitColumns: [
        {
          title: '限额',
          dataIndex: 'limitAmount'
        },
        {
          title: '规则名称',
          dataIndex: 'limitName'
        },
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ],

      serverList: [],
      serverListColumns: [
        {
          title: 'id',
          dataIndex: 'serverId'
        },
        {
          title: '供应商',
          dataIndex: 'serverName'
        },
        {
          title: '规则名称',
          dataIndex: 'limitName'
        },
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
          width: '60px'
        }
      ],

      loading: false,
      industryIdName: '',
      isEdit: true,
      yyOptions: [],
      isNeedChecked: false,
      enterpriseServerFeeRateList: [],
      gysflColums: [
      {
          title: '供应商名称',
          dataIndex: 'serverName',
          width: '120px'
        },
        {
          title: '账单方式',
          dataIndex: 'feeMode',
          scopedSlots: { customRender: 'feeMode' },
          width: '100px'
        },
        {
          title: '费率类型',
          dataIndex: 'feeRateType',
          scopedSlots: { customRender: 'feeRateType' },
          width: '100px'
        },
        {
          title: '服务费率',
          dataIndex: 'feeRate',
          scopedSlots: { customRender: 'feeRate' },
          width: '100px'
        },
        {
          title: '税率',
          dataIndex: 'taxRate',
          scopedSlots: { customRender: 'taxRate' },
          width: '80px'
       },
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ],
      allFeeList: [],
      serverFeeList: [],
      showJieti: false,
      newFeeRateRangeList: [],
    }
  },
  computed: {
    pageTypeName: function () {
      let name = ''
      if (this.$route.params.enterpriseId) {
        name = '修改'
        this.getDetail(this.$route.params.enterpriseId)
      } else {
        name = '创建'
        this.resetForm()
      }
      return name
    }
  },
  created() {
    console.log('进入')
    this.getRootData()
    if (this.$route.params.enterpriseId) {
      this.isEdit = true
    } else {
      this.isEdit = false
    }
  },
  methods: {
    yunyingFilterOption (input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      )
    },
    handleEnterpriseTypeChange(value){
      this.isNeedChecked = value != '小规模'
    },
    handleServerCollectionCreate() {
      const form = this.$refs.serverForm.form
      const servers = form.getFieldValue('servers')
      const limit = form.getFieldValue('limit')
      const limitAmount = form.getFieldValue('limitAmount') ? form.getFieldValue('limitAmount') : 98500

      for (const i in servers) {
        const rowValue = {
          serverId : '',
          serverName : '',
          limitAmount: '',
          limitName: ''
        }
        const serverTemp = servers[i].split('&')
        rowValue.serverId = serverTemp[0]
        rowValue.serverName = serverTemp[1]

        if (!limit && limitAmount){
          //自动生成规则
          rowValue.limitAmount = limitAmount
          rowValue.limitName = rowValue.serverName+'_'+limitAmount
          this.limitList.push({limitAmount:limitAmount,limitName:rowValue.limitName})
        } else {
          const limitTemp = limit.split('&')
          rowValue.limitAmount = limitTemp[0]
          rowValue.limitName = limitTemp[1]
        }

        if(this.serverList.map(s => s.serverId).indexOf(rowValue.serverId) < 0){
          this.serverList.push(rowValue)
        }
      }

      form.resetFields()
      this.collectionServerFormVisable = false
      this.checkServer()
    },
    handleServerCollectionCancel() {
      this.$refs.serverForm.form.resetFields()
      this.collectionServerFormVisable = false
    },
    showCollectionServerModel() {
      this.collectionServerFormVisable = true
      this.$refs.serverForm.show(this.limitList)
    },
    deleteServerRow(index) {
      const obj = this.serverList[index]
      let num = 0
      this.serverList.forEach((item) => {
        if (item.limitName == obj.limitName && item.limitAmount == obj.limitAmount) {
          num = num + 1
        }
      })
      if (num == 1) {
        this.limitList.forEach((item, index) => {
          if (item.limitName == obj.limitName && item.limitAmount == obj.limitAmount) {
            this.limitList.splice(index, 1)
          }
        })
      }
      this.serverList.splice(index, 1)
      this.checkServer()
    },
    checkServer() {
      if (this.serverList.length) {
        this.serverValidator = {
          help: '',
          status: 'success'
        }
      } else {
        this.serverValidator = {
          help: '请添加供应商',
          status: 'error'
        }
      }
    },
    handleLimitCollectionCreate() {
      const form = this.$refs.limitForm.form
      form.validateFields((err, values) => {
        if (!err) {
          this.limitList.push(values)
        }
      })

      form.resetFields()
      this.collectionLimitFormVisable = false
    },
    handleLimitCollectionCancel() {
      this.$refs.limitForm.form.resetFields()
      this.collectionLimitFormVisable = false
    },
    showCollectionLimitModel() {
      this.collectionLimitFormVisable = true
    },
    deleteLimitRow(index) {
      const obj = this.limitList[index]
      let num = 0
      this.serverList.forEach(item => {
        if (item.limitName == obj.limitName && item.limitAmount == obj.limitAmount) {
          num = num + 1
        }
      })
      if (num > 0) {
        this.$message.error('供应商中含有该规则名称，暂无法删除！')
      } else {
        this.limitList.splice(index, 1)
      }
      // this.limitList.splice(index, 1)
    },
    handleChange1(value) {
      console.log(value)
      this.invoiceType = value
    },
    displayRender({ labels }) {
      console.log(labels)
      return labels[labels.length - 1]
    },
    setSelectRow(value, selectedOptions) {
      if (selectedOptions) {
        const targetOption = selectedOptions
        this.hyId = targetOption[targetOption.length - 1].industryId
        // this.form.setFieldsValue({
        //   industryId: targetOption[targetOption.length - 1].industryId
        // })
      }
    },
    getChild(parentId) {
      return new Promise(resolve =>
        getIndustry(parentId).then(res => {
          if (res.resData) {
            const data = res.resData
            resolve(data)
          } else {
            this.$notification.warning({
              message: '获取分类数据出错'
            })
          }
        })
      )
    },
    getRootData() {
      this.getYYsysUsers()
      this.getChild(0).then(res => {
        this.treeData = res.map(el => Object.assign({ isLeaf: false }, el))
      })
    },
    onLoadTreeOptionData(selectedOptions) {
      const targetOption = selectedOptions[selectedOptions.length - 1]
      console.log(targetOption)
      targetOption.loading = true
      this.getChild(targetOption.industryId).then(children => {
        targetOption.children = children.map(el =>
          Object.assign(
            {
              isLeaf: true
            },
            el
          )
        )
        this.treeData = [...this.treeData]
        targetOption.loading = false
      })
    },
    //上传合同扫描件
    beforeUploadFile(file) {
      // const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'
      console.log(file)
      this.file = file
      this.defaultFileList.push(file)
      // if (!isJpgOrPng) {
      //   this.$message.error('只能上传JPG或PNG图片！')
      // }
      // const isLt2M = file.size / 1024 / 1024 < 10
      // if (!isLt2M) {
      //   this.$message.error('图片需小于10M')
      // }
      // if (isJpgOrPng && isLt2M) {
      //   this.handleFileUpload('projectAttachment')
      // }
      this.handleFileUpload('contractScanCopy')
      console.log(contractScanCopy)
      return false
    },
    handleFileUpload(fieldName) {
      const formData = new FormData()
      formData.append('mediaFile', this.file)
      this.uploadLoading = true
      uploadProjectFile(formData).then(res => {
        const filename = res.resData && res.resData.result
        this.form.setFieldsValue({
          [fieldName]: filename
        })
      }).catch(() => {
        this.defaultFileList = []
        this.$message.error('上传失败，请重试')
      }).finally(() => {
        this.uploadLoading = false
      })
    },
    removeFile() {
      this.defaultFileList = []
      this.form.resetFields('contractScanCopy')
    },


    getDetail(enterpriseId) {
      this.loading = true
      if (this.$route.params.enterpriseId) {
        this.isEdit = true
      } else {
        this.isEdit = false
      }
      getEnterpriseDetail(enterpriseId)
        .then(res => {
          this.setFieldsData(res.resData)
        })
        .finally(() => {
          this.loading = false
        })
    },
    setFieldsData(data) {
      this.$nextTick(() => {
        this.form.setFieldsValue({
          enterpriseName: data.enterpriseName,
          enterpriseSimpleName: data.enterpriseSimpleName,
          invoiceType: data.invoiceType,
          managerName: data.managerName,
          managerPhone: data.managerPhone,
          email: data.email,
          needAudit: data.needAudit,
          contractScanCopy: data.contractScanCopy,
          feeMode: data.feeMode,
          feeRateType: data.feeRateType,
          feeRate: data.feeRate && NP.times(data.feeRate,100),
          // isOpenXbd: data.isOpenXbd,
          status: data.status,
          salesName: data.salesName,
          riskScore: data.riskScore,
          riskStar: data.riskStar,
          enterpriseType: data.enterpriseType || '',
          bankName: data.bankName || '',
          bankNum: data.bankNum || '',
          phone: data.phone || '',
          unitAddress: data.unitAddress || '',
          legalPersonName: data.legalPersonName || '',
    		  legalPersonIdcardNum: data.legalPersonIdcardNum || '',
          comTaxNumber: data.comTaxNumber || '',
          unifiedSocialCreditCode: data.unifiedSocialCreditCode || '',

        })
        // if (data.isOpenXbd) {
        //   this.$nextTick(() => {
        //     this.form.setFieldsValue({
        //       userUuid: data.xbdConfig && data.xbdConfig.userUuid,
        //       userToken: data.xbdConfig && data.xbdConfig.userToken
        //     })
        //   })
        // }


           // 供应商费率 start
        this.serverFeeList = []
        if (data.enterpriseServerFeeRateList.length > 0) {
          data.enterpriseServerFeeRateList.forEach(i => {
            if (i.serverId) {
              getServerFeeList({serverId:i.serverId}).then(res => {
              const obj = {
                serverName: res.resData.serverName,
                feeMode: i.feeMode,
                feeRateType: 1,
                serverId: i.serverId,
                feeRate: parseFloat((i.feeRate * 100).toFixed(10)),
                taxRate: i.taxRate,
                xbdContractUuid: i.xbdContractUuid || ''
              }
              this.serverFeeList.push(obj)
            })
            }
          
          })
        }
        // this.feeRateRangeList = data.feeRateRangeList || []
        this.feeRateRangeList = []
        var map = {}
        var dest = []
        if (data.feeRateRangeList.length > 0) {
          // for(var i = 0; i < data.feeRateRangeList.length; i++){
          //   var ai = data.feeRateRangeList[i]
          //   if(!map[ai.serverId]){
          //       dest.push({
          //             serverId: ai.serverId,
          //             serverName: '',
          //             feeMode: ai.feeMode,
          //             feeRateType: 2,
          //             feeRateList: [ai],
          //             taxRate: ai.taxRate,
          //             xbdContractUuid: ai.xbdContractUuid || ''
          //         })
          //         map[ai.serverId] = ai
          //   }else{
          //       for(var j = 0; j < dest.length; j++){
          //           const dj = dest[j]
          //           if(dj.serverId == ai.serverId){
          //               dj.feeRateList.push(ai)
          //               break
          //           }
          //       }
          //   }
          // }
          const dataArr = []
          data.feeRateRangeList.map(mapItem => {
              if (dataArr.length == 0) {
                // date: mapItem.date, List: [mapItem]
                  dataArr.push({ 
                    serverId: mapItem.serverId,
                    serverName: '',
                    feeRateType: 2,
                    feeRate: mapItem.feeRate,
                    taxRate: mapItem.taxRate,
                    xbdContractUuid: '',
                    feeMode: mapItem.feeMode,
                    feeRateList: [mapItem]
                  })
              } else {
                const res = dataArr.some(item=> {//判断相同日期，有就添加到当前项
                  if (item.taxRate == mapItem.taxRate && item.serverId == mapItem.serverId) {
                    item.feeRateList.push(mapItem)
                    return true
                  }
                })
                console.log(dataArr)
                console.log(res)
                if (!res) {//如果没找相同日期添加一个新对象
                  dataArr.push({ 
                    serverId: mapItem.serverId,
                    serverName: '',
                    feeRateType: 2,
                    feeRate: mapItem.feeRate,
                    taxRate: mapItem.taxRate,
                    xbdContractUuid: mapItem.xbdContractUuid,
                    feeMode: mapItem.feeMode,
                    feeRateList: [mapItem]
                  })
                }
              }
            })
            // console.log(this.feeRateFixList)
            // this.feeRateFixList = [...this.feeRateFixList, ...dataArr]
            dest = dataArr
        }
        // console.log(...dest)
        dest.forEach((i,index) => {
          if (i.serverId) {
            getServerFeeList({serverId:i.serverId}).then(res => {
                  const serverName = res.resData.serverName
                  dest[index].serverName = serverName
                })
          }
           
        })
        console.log(dest)
        // return
        // this.feeRateRangeList = dest
        // let arr1 = []
        this.serverFeeList = [...this.serverFeeList, ...dest]
        // arr1 = this.serverFeeList.concat(this.dest)
        // data.feeRateRangeList.forEach((item, index) => {
        //   data.feeRateRangeList[index].feeRateType = 2
        // })
        // data.enterpriseServerFeeRateList.forEach((item, index) => {
        //   data.enterpriseServerFeeRateList[index].feeRateType = 1
        // })
        // let arr1 = this.serverFeeList
        // let arr = JSON.parse(JSON.stringify(arr1))
        // this.backTableList(arr)
       
       
        // 供应商费率 end

        if (data.operationsManagerId) {
          this.form.setFieldsValue({
            operationsManagerName: data.operationsManagerName,
            operationsManagerId: data.operationsManagerId+'',
          })
        } 
        this.industryIdName = data.industryName
        this.hyId = data.industryId
        this.feeRateType = data.feeRateType
        this.feeRateRangeList = data.feeRateRangeList || []
        this.serverList = data.serverList || []
        this.serverList.forEach(item => item.limitAmount = item.limitAmount/100)
        this.limitList = data.limitList || []
        this.limitList.forEach(item => item.limitAmount = item.limitAmount/100)
      })
    },
    handleSubmit(e) {
      e.preventDefault()
      this.checkFeeRange()
      this.checkServer()
      this.form.validateFields((err, values) => {
        if (!err) {
          if (this.$route.params.enterpriseId) {
            values.enterpriseId = this.$route.params.enterpriseId
          }
          if (values.feeRateType === 1) {
            values.feeRate = NP.divide(values.feeRate,100)
          } else {
            values.feeRate = null
            values.feeRateRangeList = this.feeRateRangeList
          }
          values.serverList = cloneDeep(this.serverList)
          values.serverList.forEach(item => item.limitAmount = item.limitAmount*100)
          values.monthLimitAmount = (values.monthLimitAmount?values.monthLimitAmount:98500)*100
          console.log('Received values of form: ', values)
          values.industryId = this.hyId
          values.limitList = cloneDeep(this.limitList)
          values.limitList.forEach(item => item.estimateFee = item.estimateFee * 100)

          // 供应商费率  - start
          const params = {}
          if (this.serverFeeList.length == 0) {
            this.$message.error('请添加供应商费率！')
            return
          }
          if (this.serverFeeList.length > 0) {
            var check = true
            params.enterpriseServerFeeRateList = []
            params.feeRateRangeList = []
            this.serverFeeList.forEach((i,index) => {
              if (i.feeRateType == 1) {
                const obj = {
                  serverId: i.serverId,
                  feeRate: parseFloat((i.feeRate / 100).toFixed(10)),
                  feeMode: i.feeMode,
                  taxRate: i.taxRate,
                  // xbdContractUuid: i.xbdContractUuid
                }
                
                params.enterpriseServerFeeRateList.push(obj)
              } else {
                if (i.feeRateList.length > 0) {
                  i.feeRateList.forEach(j => {
                  const obj1 = {
                    serverId: i.serverId,
                    feeRate: j.feeRate,
                    amountLow: j.amountLow,
                    amountHigh: j.amountHigh,
                    feeMode: i.feeMode,
                    taxRate: i.taxRate,
                    // xbdContractUuid: i.xbdContractUuid || ''
                  }
                  // if (i.xbdContractUuid) {
                  //   obj1.xbdContractUuid = i.xbdContractUuid
                  // }
                  params.feeRateRangeList.push(obj1)
                })
                }
                
              }
              
              if (index == this.serverFeeList.length - 1) {
                // console.log(values)
                if (params.enterpriseServerFeeRateList.length == 0 && params.feeRateRangeList.length == 0) {
                  return
                }
                // if (this.serverList.length != this.enterpriseServerFeeRateList.length) {
                //   this.$message.error('供应商不一致！')
                //   return
                // } else {
                  const arr1 = []
                  const arr2 = []
                  this.serverFeeList.forEach(i => {
                    arr1.push(parseInt(i.serverId))
                  })
                  this.serverList.forEach(i => {
                    arr2.push(parseInt(i.serverId))
                  })
                  // console.log(this.enterpriseServerFeeRateList)
                  // console.log(this.serverList)
                  // console.log(arr1)
                  // console.log(arr2)
                  const arr3 = []
                  const arr4 = []
                  var flag = true
                  arr1.forEach(item => {
                    // console.log(item)
                    if (arr2.indexOf(item) === -1) {
                      flag = false
                      arr3.push(item)
                    }
                  })
                  var flag1 = true
                  console.log(arr3)
                  console.log(arr1)
                  console.log('你好世界')
                  this.serverFeeList.forEach(item => {
                    if (item.serverId == arr3[0]) {
                      flag1 = false
                      this.$message.error(item.serverName+'供应商没有配置限额！')
                      return
                    }
                  })
                  if (flag1 == false) {
                    check = false
                    return
                  }
                  arr2.forEach(item => {
                    // console.log(item)
                    if (arr1.indexOf(item) === -1) {
                      flag = false
                      arr4.push(item)
                    }
                  })
                  var flag2 = true
                  if (flag == false) {
                    this.serverList.forEach(item => {
                      if (item.serverId == arr4[0]) {
                        flag2 = false
                        this.$message.error(item.serverName+'供应商没有配置费率！')
                        return
                      }
                    })
                  }
                  if (flag2 == false) {
                    check = false
                    return
                  }
                  // this.doSubmit(params)
                // }
              }
            
            })
            if (!check) {
              return
            }
          }
          
          // 供应商费率  - end
          values.enterpriseServerFeeRateList = params.enterpriseServerFeeRateList
          values.feeRateRangeList = params.feeRateRangeList
          this.doSubmit(values)
        }
      })
    },
    doSubmit(values) {
      const postMethod = this.$route.params.enterpriseId ? updateEnterprise : addEnterprise
      this.loading = true
      postMethod(values)
        .then(res => {
          console.log(res)
          this.$message.success(`${this.pageTypeName}成功`)
          this.$router.push('/enterprise/list')
        })
        .catch(err => {
          console.log(err)
          this.$message.error(`${this.pageTypeName}失败`)
        })
        .finally(() => {
          this.loading = false
        })
    },
    showCollectionModel() {
      this.collectionFormVisable = true
    },
    handleCollectionCancel() {
      this.$refs.collectionForm.form.resetFields()
      this.collectionFormVisable = false
    },
    handleCollectionCreate() {
      const form = this.$refs.collectionForm.form
      form.validateFields((err, values) => {
        if (err) {
          return
        }
        const arrayLength = this.feeRateRangeList.length
        if (
          arrayLength &&
          values.amountHigh * 100 !== this.feeRateRangeList[0].amountLow &&
          values.amountLow * 100 !== this.feeRateRangeList[arrayLength - 1].amountHigh
        ) {
          this.$message.error('请确保费率区间连续')
          return
        }
        // console.log('Received values of form: ', values)
        values.amountHigh *= 100
        values.amountLow *= 100
        values.feeRate = NP.divide(values.feeRate,100)
        this.feeRateRangeList.push(values)
        this.feeRateRangeList.sort((a, b) => a.amountLow - b.amountLow)
        form.resetFields()
        this.checkFeeRange()
        this.collectionFormVisable = false
      })
    },
    deleteFeeRangeRow(index) {
      const that = this
      this.$confirm({
        title: '删除提示',
        content: '确认删除这条数据吗？',
        onOk() {
          that.$message.success('删除成功')
          that.feeRateRangeList.splice(index, 1)
          that.checkFeeRange()
        },
        onCancel() { }
      })
      // this.feeRateRangeList.splice(index, 1)
      // this.checkFeeRange()
    },
    setFeeRateType(event) {
      this.feeRateType = event.target.value
    },
    checkFeeRange() {
      if (this.feeRateRangeList.length) {
        this.feeRangeValidator = {
          help: '',
          status: 'success'
        }
      } else {
        this.feeRangeValidator = {
          help: '请添加阶梯费率',
          status: 'error'
        }
      }
    },
    resetForm() {
      if (this.$route.params.enterpriseId) {
        this.isEdit = true
      } else {
        this.isEdit = false
      }
      this.form.resetFields()
    },
    handleChange(value) {
      console.log(value)
      this.operationsManagerName = this.yyOptions.filter(item => item.userId === value)[0]['realName']
    },
    getYYsysUsers() {
      getYYsysUsers().then(res => {
        this.yyOptions = res.resData
        if (this.form.getFieldValue('operationsManagerId')) {
          let check = false
          this.yyOptions.forEach(item => {
            if (item.userId  == this.form.getFieldValue('operationsManagerId')) {
              check = true
            }
          })
          if (!check) {
            this.yyOptions.push({ phone: null, realName: this.operationsManagerName, role: null, status: null, userId: null, userType: null, username: this.operationsManagerName })
          }
        }

      })
    },
    showserverFeeFormVisable () {
      const params = {}
      if (this.$route.params.enterpriseId) {
        const dataInfo = {}
        const list = this.serverFeeList
          const resData = list
          list.forEach((item1, index1) => {
            const serverId = item1.serverId
            if (!dataInfo[serverId]) {
              dataInfo[serverId] = {
                serverId,			
                priceTable: []
              }
            }
            dataInfo[serverId].priceTable.push(item1)
          })
          const newlist = Object.values(dataInfo)
          newlist.forEach((item2, index2) => {
            getServerFeeList({serverId: item2.serverId}).then(res => {
              const serverName = res.resData.serverName
              this.$set(newlist[index2], 'serverName', serverName)
            })
          })
          this.allFeeList = newlist
          this.collectionServerFeeFormVisable = true
          console.log(this.allFeeList)
        this.$refs.serverFeeForm.getServers(this.allFeeList)
        this.$refs.serverFeeForm.getInfo(params)
      } else {
        this.collectionServerFeeFormVisable = true
      this.$refs.serverFeeForm.getServers(this.allFeeList)
      this.$refs.serverFeeForm.getInfo(params)
      }
      
    },
    handleLimitFeeFormCancel () {
      this.$refs.serverFeeForm.resetForm()
      this.collectionServerFeeFormVisable = false
    },
    handleLimitFeeFormCreate (info, index) {
      console.log('接收传值')
      console.log(info)
      console.log(index)
      console.log('接收传值')
      const check = true
      
      // this.allFeeList = 
      // this.enterpriseServerFeeRateList.forEach(i => {
      //   if (i.serverName == info.serverName) {
      //     check = false
      //   }
      // })
      // this.feeRateRangeList.forEach(i => {
      //   if (i.serverName == info.serverName) {
      //     check = false
      //   }
      // })
      if (index == -1) {
        if (check) {
          this.allFeeList.push(info) 
          this.enterpriseServerFeeRateList.push(info)
          this.handleLimitFeeFormCancel()
        } else {
          this.$message.error('该供应商费率已被选择，请勿重复选择！')
          return
        }
      } else {
        this.allFeeList[index] = info
        this.handleLimitFeeFormCancel()
      }
      console.log(this.allFeeList)
      this.serverFeeList = []
      // if (index == -1) {
        
        this.allFeeList.forEach(item => {
          item.priceTable.forEach(item1 => {
            const commentInfo  = {
              serverName: item.serverName,
              serverId: item.serverId
            }
            const obj = {...commentInfo, ...item1}
            this.serverFeeList.push(obj)
          })
          
          // if (item.feeRateType == 1) {
          //   this.enterpriseServerFeeRateList.push(item)
          // } else {
          //   this.feeRateRangeList.push(item)
          // }
        })
      // }
      
     
      console.log(this.enterpriseServerFeeRateList)
      // this.FeeRateColumns = this.enterpriseServerFeeRateList
      // const form = this.$refs.serverFeeForm.form
      // console.log(form)
    },
    lookJiage (info, index) {
      const params = {}
      let info2 = {}
      this.allFeeList.forEach((item, index1) => {
        if (item.serverId == info.serverId) {
          info2 = item
          index = index1
        }
      })
      this.collectionServerFeeFormVisable = true
      this.$refs.serverFeeForm.getInfo(params, info2, index)
    },
    editFeeRate (info, index) {
      if (this.$route.params.enterpriseId) {
        this.backTableList(this.serverFeeList, info, index)
      } else {
        this.lookJiage(info,index)
      }
      // let params = {}
      // if (this.form.getFieldValue('isOpenXbd')) {
      //   params = {
      //     xbdUserUuid: this.form.getFieldValue('xbdUserUuid'),
      //     xbdToken: this.form.getFieldValue('xbdToken'),
      //     isOpenXbd: this.form.getFieldValue('isOpenXbd')
      //   }
      // }
      // let arr = []
      //   let str = ''
      //   this.priceTable.forEach((item, index1) => {
      //     if (index1 != index) {
      //       arr.push(item.taxRate)
      //     }
      //   })
      //   str = arr.join(',')
      // this.$refs.priceInfo(params， info, index)
    },
    backTableList (list, info, index) {
      console.log(list)
          const dataInfo = {}
          // let resData = list
          list.forEach((item1, index1) => {
            const serverId = item1.serverId
            if (!dataInfo[serverId]) {
              dataInfo[serverId] = {
                serverId,			
                priceTable: []
              }
            }
            dataInfo[serverId].priceTable.push(item1)
          })
          const newlist = Object.values(dataInfo)
          newlist.forEach((item2, index2) => {
            getServerFeeList({serverId: item2.serverId}).then(res => {
              const serverName = res.resData.serverName
              this.$set(newlist[index2], 'serverName', serverName)
            })
          })
          this.allFeeList = newlist
          if (info) {
            this.lookJiage(info,index)
          }
          console.log(newlist)
      
    },
    deleteServerFeeRow (info, index) {
      this.serverFeeList.splice(index, 1)
      this.allFeeList.forEach((item, index) => {
        if (info.serverName == item.serverName) {
          item.priceTable.forEach((item1, index1) => {
            if (item1.taxRate == info.taxRate) {
              this.allFeeList[index].priceTable.splice(index1,1)
              if (this.allFeeList[index].priceTable.length == 0) {
                this.allFeeList.splice(index, 1)
              }
            }
          })
        }
      })
      console.log(this.allFeeList)
    }
  }
}
</script>
